package com.easy.controller;


import com.easy.bean.Pay;
import com.easy.service.PayService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("pay")
public class PayController {
    @Autowired
    PayService payService;

    @PostMapping
    public Result add(@RequestBody Pay pay) {
        Object obj = payService.add(pay);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Pay pay) {
        Object obj = payService.edit(pay);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable(name = "id") Integer id) { // 关键修复：显式指定name
        Object obj = payService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = payService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Pay pay) {  // 去掉 @RequestBody，Spring 会自动绑定请求参数
        Object obj = payService.all(pay);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Pay pay) {
        //查询一共多少页，多少条数据
        //查询当前页要显示的数据
        //封装数据到page对象中
        //返回page对象
        payService.page(page, pay);
        return Result.success(page);
    }
}